home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Compilers / digital marsC compier / dm / stl / stl_stack.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-08  |  4.2 KB  |  144 lines

  1. /*
  2.  *
  3.  * Copyright (c) 1994
  4.  * Hewlett-Packard Company
  5.  *
  6.  * Permission to use, copy, modify, distribute and sell this software
  7.  * and its documentation for any purpose is hereby granted without fee,
  8.  * provided that the above copyright notice appear in all copies and
  9.  * that both that copyright notice and this permission notice appear
  10.  * in supporting documentation.  Hewlett-Packard Company makes no
  11.  * representations about the suitability of this software for any
  12.  * purpose.  It is provided "as is" without express or implied warranty.
  13.  *
  14.  *
  15.  * Copyright (c) 1996,1997
  16.  * Silicon Graphics Computer Systems, Inc.
  17.  *
  18.  * Permission to use, copy, modify, distribute and sell this software
  19.  * and its documentation for any purpose is hereby granted without fee,
  20.  * provided that the above copyright notice appear in all copies and
  21.  * that both that copyright notice and this permission notice appear
  22.  * in supporting documentation.  Silicon Graphics makes no
  23.  * representations about the suitability of this software for any
  24.  * purpose.  It is provided "as is" without express or implied warranty.
  25.  */
  26.  
  27. /* NOTE: This is an internal header file, included by other STL headers.
  28.  *   You should not attempt to use it directly.
  29.  */
  30.  
  31. #ifndef __SGI_STL_INTERNAL_STACK_H
  32. #define __SGI_STL_INTERNAL_STACK_H
  33.  
  34. #include <sequence_concepts.h>
  35.  
  36. __STL_BEGIN_NAMESPACE
  37.  
  38. // Forward declarations of operators == and <, needed for friend declaration.
  39.  
  40. template <class _Tp, 
  41.           class _Sequence __STL_DEPENDENT_DEFAULT_TMPL(deque<_Tp>) >
  42. class stack;
  43.  
  44. template <class _Tp, class _Seq>
  45. bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y);
  46.  
  47. template <class _Tp, class _Seq>
  48. bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y);
  49.  
  50.  
  51. template <class _Tp, class _Sequence>
  52. class stack {
  53.  
  54.   // requirements:
  55.  
  56.   __STL_CLASS_REQUIRES(_Tp, _Assignable);
  57.   __STL_CLASS_REQUIRES(_Sequence, _BackInsertionSequence);
  58.   typedef typename _Sequence::value_type _Sequence_value_type;
  59.   __STL_CLASS_REQUIRES_SAME_TYPE(_Tp, _Sequence_value_type);
  60.  
  61.  
  62. #ifdef __STL_MEMBER_TEMPLATES
  63.   template <class _Tp1, class _Seq1>
  64.   friend bool operator== (const stack<_Tp1, _Seq1>&,
  65.                           const stack<_Tp1, _Seq1>&);
  66.   template <class _Tp1, class _Seq1>
  67.   friend bool operator< (const stack<_Tp1, _Seq1>&,
  68.                          const stack<_Tp1, _Seq1>&);
  69. #else /* __STL_MEMBER_TEMPLATES */
  70.   friend bool __STD_QUALIFIER
  71.   operator== __STL_NULL_TMPL_ARGS (const stack&, const stack&);
  72.   friend bool __STD_QUALIFIER
  73.   operator< __STL_NULL_TMPL_ARGS (const stack&, const stack&);
  74. #endif /* __STL_MEMBER_TEMPLATES */
  75.  
  76. public:
  77.   typedef typename _Sequence::value_type      value_type;
  78.   typedef typename _Sequence::size_type       size_type;
  79.   typedef          _Sequence                  container_type;
  80.  
  81.   typedef typename _Sequence::reference       reference;
  82.   typedef typename _Sequence::const_reference const_reference;
  83. protected:
  84.   _Sequence c;
  85. public:
  86.   stack() : c() {}
  87.   explicit stack(const _Sequence& __s) : c(__s) {}
  88.  
  89.   bool empty() const { return c.empty(); }
  90.   size_type size() const { return c.size(); }
  91.   reference top() { return c.back(); }
  92.   const_reference top() const { return c.back(); }
  93.   void push(const value_type& __x) { c.push_back(__x); }
  94.   void pop() { c.pop_back(); }
  95. };
  96.  
  97. template <class _Tp, class _Seq>
  98. bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
  99. {
  100.   return __x.c == __y.c;
  101. }
  102.  
  103. template <class _Tp, class _Seq>
  104. bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
  105. {
  106.   return __x.c < __y.c;
  107. }
  108.  
  109. #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
  110.  
  111. template <class _Tp, class _Seq>
  112. bool operator!=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
  113. {
  114.   return !(__x == __y);
  115. }
  116.  
  117. template <class _Tp, class _Seq>
  118. bool operator>(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
  119. {
  120.   return __y < __x;
  121. }
  122.  
  123. template <class _Tp, class _Seq>
  124. bool operator<=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
  125. {
  126.   return !(__y < __x);
  127. }
  128.  
  129. template <class _Tp, class _Seq>
  130. bool operator>=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
  131. {
  132.   return !(__x < __y);
  133. }
  134.  
  135. #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
  136.  
  137. __STL_END_NAMESPACE
  138.  
  139. #endif /* __SGI_STL_INTERNAL_STACK_H */
  140.  
  141. // Local Variables:
  142. // mode:C++
  143. // End:
  144.